package main

import (
	"bytes"
	"fmt"
	"path/filepath"
	"text/template"
)

type FieldInfo struct {
	FieldDesc string
	FieldType string
	FieldJson string
	DictType  bool
}

var fns = template.FuncMap{
	"sub": func(a, b int) int {
		return a - b
	},
}

func main() {
	fmt.Println(filepath.Base("resource/template/hello4.tpl"))
	tmpl, err := template.New("hello4.tpl").Funcs(fns).ParseFiles("resource/template/hello4.tpl")
	fmt.Println(err)
	f1 := FieldInfo{
		FieldDesc: "名字",
		FieldType: "string",
		FieldJson: "name",
	}
	f2 := FieldInfo{
		FieldDesc: "年龄",
		FieldType: "int",
		FieldJson: "age",
	}
	var fs []FieldInfo
	fs = append(fs, f1)
	fs = append(fs, f2)
	var body bytes.Buffer
	err = tmpl.Execute(&body, fs)
	fmt.Println(body.String())
	fmt.Println(err)

}
